package com.young.springdemo.service.prototypePattern;

import lombok.Data;

import java.io.*;

//实现深度克隆的实体类
@Data
public class DayLog implements Serializable{

    private String name;
    private String user;
    private Attachment attachment;

    public DayLog clone(){
        try {
            //将对象写入流
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bao);
            oos.writeObject(this);
            //将对象写入流
            ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            return (DayLog)ois.readObject();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
